# 网络请求相关方法
import json

import requests
import urllib3

urllib3.disable_warnings()  # 禁止错误提示

proxies = {}  # 代理配置

head = ('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',  # google
        'Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)',  # 雅虎
        'Sogou Push Spider/3.0(+http://www.sogou.com/docs/help/webmasters.htm#07)',  # 搜狗
        'Mozilla/5.0 (compatible; YodaoBot/1.0;http://www.yodao.com/help/webmaster/spider/;)',  # 有道
        'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)'  # 百度
        )  # 搜索引擎user-agent

# 请求头信息
global_headers = {
    'User-Agent': head[0]
}


def get(url='', option='', headers={}):
    headers = dict(global_headers, **headers)
    r = requests.get(url=url, params=option, headers=headers, proxies=proxies, verify=False)
    return r


def post(url='', option={}, headers={}):
    headers = dict(global_headers, **headers)
    r = requests.post(url=url, data=json.dumps(option), headers=headers, proxies=proxies, verify=False)
    return r
